from typing import Dict, Any
from dataclasses import dataclass, replace

@dataclass(frozen=True)
class AppState:
    """不可变应用状态"""
    user: Dict[str, Any]
    settings: Dict[str, Any]

    def update_user(self, updates: Dict[str, Any]) -> 'AppState':
        """更新用户信息，返回新状态"""
        new_user = {**self.user, **updates}
        return replace(self, user=new_user)